<?php


namespace app\crontab\controller\once;


use custom\Mongo;
use think\console\Command;
use think\console\Input;
use think\console\Output;

/**
 * 小学小区同步
 * Class SchoolPrimaryVillageSync
 * @package app\crontab\controller
 */
class SchoolPrimaryVillageSync   extends Command {


    protected function configure() {
        $this->setName('SchoolPrimaryVillageSync');
    }

    protected function execute(Input $input, Output $output) {
        echo "start\n";
        $mongo = Mongo::getInstance();
        $cursor = $mongo->select('SchoolPrimaryVillage', ['v_id'=>['$gt'=>0]], ['sort' => ['id' => 1]]);
        foreach ($cursor as $k => $v) {
            $xx_id = db("school_primary")->where('mongo_id', $v->xx_id)->value('id');
            $data = [
                'id'         => md5($xx_id . '-' . $v->v_id),
                'primary_id' => $xx_id,
                'village_id'  => $v->v_id,
            ];
            db("school_primary_village")->insert($data);
        }
        echo "end\n";
    }

}